home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / envy / instun / classes.py < prev    next >
Encoding:
Python Source  |  2007-05-15  |  50.5 KB  |  1,170 lines

  1. #!/usr/bin/env python
  2. #Developed by Alberto Milone (aka tseliot)
  3.  
  4. import sys
  5. import commands
  6. import string
  7. import os, popen2, fcntl, fcntl, select
  8. from os.path import isfile
  9. import shutil
  10. import fileinput, re
  11. import main
  12. import objects
  13.  
  14. atimanlatest = '8.36.5'
  15. atimanlegacy = '8.28.8'
  16. nvmanlatest = '9755'
  17. nvmannewlegacy = '9631'
  18. nvmanlegacy = '7185'
  19.  
  20. class Compatibcheck:
  21.     #def init(self):
  22.     #    self.brandname = 'none'# either "Nvidia" or "ATI"
  23.         
  24.     def check(self):#oldname "checkcompatib()"
  25.         a = main.getCommandOutput('lspci | grep "VGA"')
  26.         b = a.lower().split(' ')
  27.         c = self.brandname.lower()
  28.         if c not in b:#if there's no trace of either ati or nvidia in the output
  29.             print 'ENVY ERROR: ' + self.brandname + ' card not found'
  30.             event = 'error'
  31.         else:
  32.             event = 'passed'
  33.         return event
  34.  
  35. class Specsdetect:
  36.  
  37.     def init(self):
  38.     #    self.cards = {}
  39.     #    self.middlecards = {}
  40.     #    self.legacycards = {}
  41.         self.details = {}#all the details about the card, driver, arch are stored here
  42.     
  43.     def codename(self):
  44.         """
  45.         Get system codename, can be warty/hoary/breezy/dapper/edgy/etch
  46.         """
  47.         p = os.popen("lsb_release -c")
  48.         try:
  49.             codename = p.readline().strip()
  50.             tokens = codename.split("\t")
  51.         finally:
  52.             p.close()
  53.         self.details['osname'] = tokens[-1].lower()
  54.         self.legacyos = ['dapper', 'etch']
  55.         #return osname
  56.         #self.details['osname'] = osname#formerly known as "systemname"
  57.     
  58.     def architecture(self):
  59.         """
  60.         Detect whether the architecture is x86/ppc/amd64 
  61.         """
  62.         arch = os.uname()[-1]
  63.         if arch in ('ppc', 'ppc64'):
  64.             arch = 'powerpc'
  65.         elif arch =='x86_64':
  66.             arch = 'x86_64'
  67.         elif arch in ('i386','i686','i586','k7'):
  68.             arch = 'x86'
  69.         #return arch
  70.         self.details['arch'] = arch#formerly known as "arca"
  71.     
  72.     def systemcheck(self):#It is based upon details[0] and details[1]
  73.         if self.details['osname'] == 'dapper':
  74.             if self.details['arch'] == 'x86':
  75.                 print 'Ubuntu Dapper 32bit'
  76.             elif self.details['arch'] == 'x86_64':
  77.                 print 'Ubuntu Dapper 64bit' 
  78.             else:
  79.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  80.                 sys.exit()
  81.         elif self.details['osname'] == 'edgy':#SUPPORT FOR EDGY
  82.             if self.details['arch'] == 'x86':
  83.                 print 'Ubuntu Edgy 32bit'
  84.             elif self.details['arch'] == 'x86_64':
  85.                 print 'Ubuntu Edgy 64bit' 
  86.             else:
  87.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  88.                 sys.exit()
  89.         elif self.details['osname'] == 'feisty':#SUPPORT FOR FEISTY
  90.             if self.details['arch'] == 'x86':
  91.                 print 'Ubuntu Feisty 32bit'
  92.             elif self.details['arch'] == 'x86_64':
  93.                 print 'Ubuntu Feisty 64bit' 
  94.             else:
  95.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  96.                 sys.exit()
  97.         elif self.details['osname'] == 'cassandra':#SUPPORT FOR LINUX MINT CASSANDRA
  98.             self.details['osname'] = 'feisty'#this will make it act like feisty
  99.             if self.details['arch'] == 'x86':
  100.                 print 'Linux Mint Cassandra 32bit'
  101.             elif self.details['arch'] == 'x86_64':
  102.                 print 'Linux Mint Cassandra 64bit' 
  103.             else:
  104.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  105.                 sys.exit()
  106.         elif self.details['osname'] == 'etch':#SUPPORT FOR ETCH
  107.             if self.details['arch'] == 'x86':
  108.                 print 'Debian Etch 32bit'
  109.             elif self.details['arch'] == 'x86_64':
  110.                 print 'Debian Etch 64bit' 
  111.             else:
  112.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  113.                 sys.exit()
  114.  
  115.         else:
  116.             print "ENVY ERROR: Your Operative System does not seem to be supported by Envy"
  117.             sys.exit()
  118.     
  119.     def drivertype(self):
  120.         geforcego = ['0112', '0172', '0174', '0175', '0176', '0177', '0179', '0286', '017d' ]#need to use dfp
  121.         availabledrv = []#the list of drivers which your system supports
  122.         syscards = main.getCommandOutput('lspci -n | grep "0300" | cut -d " " -f3 | sed s/.*://').strip().lower()
  123.         systemcards = syscards.split('\n')
  124.         for element in systemcards:
  125.             try:
  126.                 systemcards.remove('\n')
  127.             except ValueError:
  128.                 pass
  129.         for card in systemcards:
  130.             if card in geforcego:
  131.                 self.details['geforcego'] = 'true'#will be used by nvxorgset
  132.             #detect the card and choose the driver accordingly
  133.             if self.cards.setdefault(card, 'N/A') != 'N/A':
  134.                 print 'Your graphic card has been detected as a ' + self.cards[card]
  135.                 print 'Your graphic card is supported by the latest driver'
  136.                 drvtype = 'latest'
  137.             elif self.middlecards.setdefault(card, 'N/A') != 'N/A':
  138.                 print 'Your graphic card has been detected as a ' + self.middlecards[card]
  139.                 print 'Your graphic card is supported by the new legacy driver'
  140.                 drvtype = 'middle'
  141.             elif self.legacycards.setdefault(card, 'N/A') != 'N/A':
  142.                 print 'Your graphic card has been detected as a ' + self.legacycards[card]
  143.                 print 'Your graphic card is supported by the legacy Driver'
  144.                 drvtype = 'oldest'
  145.             else:
  146.                 drvtype = 'unsupported'
  147.             availabledrv.append(drvtype)
  148.         if 'latest' in availabledrv:#select the driver following this priority: latest, middle, oldest
  149.             self.details['drvtype'] = 'latest'
  150.         else:
  151.             if 'middle' in availabledrv:
  152.                 self.details['drvtype'] = 'middle'
  153.             else:
  154.                 if 'oldest' in availabledrv:
  155.                     self.details['drvtype'] = 'oldest'
  156.                 else:#if the CARD is NOT SUPPORTED
  157.                     print 'ENVY ERROR: Envy does not recognise your card as compatible with any version of the driver.\
  158.                     this might happen because either your card is not supported by the driver or Envy\'s hardware\
  159.                     detection failed. You can try the manual installation at your risk.'
  160.                     sys.exit()
  161.                     #while 1:#If the id of the card is not in the list
  162.                     #    unsupported = raw_input('\nYour graphic card does not seem to be supported by the driver.\n\n\
  163.                     #                   Would you like to go ahead with the installation even if, according to Envy, your card is not supported?\n\
  164.                     #                   (Type either "yes" or "no")\n').strip()
  165.                     #    if unsupported == 'yes':
  166.                     #        break
  167.                     #    elif unsupported == 'no':
  168.                     #        sys.exit()
  169.                     #        break
  170.                     #self.details['drvtype'] = 'latest'
  171.     
  172.     
  173.     def geforcegocheck(self):
  174.         geforcego = ['0112', '0172', '0174', '0175', '0176', '0177', '0179', '0286', '017d' ]#need to use dfp
  175.         availabledrv = []#the list of drivers which your system supports
  176.         systemcards = []
  177.         p = os.popen('lspci -n')
  178.         indentifier1 = re.compile('.*0300:.*:(.+) \(.+\)\n')
  179.         indentifier2 = re.compile('.*0300:.*:(.+)\n')
  180.         for line in p:#self.completetxt:#self.logged:
  181.             m1 = indentifier1.match(line)
  182.             m2 = indentifier2.match(line)
  183.             if m1:
  184.                 id = m1.group(1).strip().lower()
  185.                 systemcards.append(id)
  186.             elif m2:
  187.                 id = m2.group(1).strip().lower()
  188.                 systemcards.append(id)
  189.         for card in systemcards:
  190.             if card in geforcego:
  191.                 self.details['geforcego'] = 'true'#will be used by nvxorgset
  192.     
  193.     
  194.     
  195.     
  196.     def driverpushback(self):
  197.         availabledrv = []#the list of drivers which your system supports
  198.         #syscards = main.getCommandOutput('lspci -n | grep "0300" | cut -d " " -f3 | sed s/.*://').strip().lower()
  199.         #systemcards = syscards.split('\n')
  200.         #for element in systemcards:
  201.         #    try:
  202.         #        systemcards.remove('\n')
  203.         #    except ValueError:
  204.         #        pass
  205.         systemcards = []
  206.         p = os.popen('lspci -n')
  207.         indentifier1 = re.compile('.*0300:.*:(.+) \(.+\)\n')
  208.         indentifier2 = re.compile('.*0300:.*:(.+)\n')
  209.         for line in p:#self.completetxt:#self.logged:
  210.             m1 = indentifier1.match(line)
  211.             m2 = indentifier2.match(line)
  212.             if m1:
  213.                 id = m1.group(1).strip().lower()
  214.                 systemcards.append(id)
  215.             elif m2:
  216.                 id = m2.group(1).strip().lower()
  217.                 systemcards.append(id)
  218.  
  219.  
  220.         for card in systemcards:
  221.             #detect the card and choose the driver accordingly
  222.             if self.cards.setdefault(card, 'N/A') != 'N/A':
  223.                 #print 'Your graphic card has been detected as a ' + self.cards[card]
  224.                 #print 'Your graphic card is supported by the latest driver'
  225.                 drvtype = 'latest'
  226.             elif self.middlecards.setdefault(card, 'N/A') != 'N/A':
  227.                 #print 'Your graphic card has been detected as a ' + self.middlecards[card]
  228.                 #print 'Your graphic card is supported by the new legacy driver'
  229.                 drvtype = 'middle'
  230.             elif self.legacycards.setdefault(card, 'N/A') != 'N/A':
  231.                 #print 'Your graphic card has been detected as a ' + self.legacycards[card]
  232.                 #print 'Your graphic card is supported by the legacy Driver'
  233.                 drvtype = 'oldest'
  234.             else:
  235.                 drvtype = 'unsupported'
  236.             availabledrv.append(drvtype)
  237.         if 'latest' in availabledrv:#select the driver following this priority: latest, middle, oldest
  238.             self.details['drvtype'] = 'latest'
  239.         else:
  240.             if 'middle' in availabledrv:
  241.                 self.details['drvtype'] = 'middle'
  242.             else:
  243.                 if 'oldest' in availabledrv:
  244.                     self.details['drvtype'] = 'oldest'
  245.     
  246.     def atimanver(self):
  247.         while 1:
  248.             drvchoice = raw_input('\n\
  249.                 Select the version of the driver which would you like to install:\n\
  250.                 1 - ' + atimanlatest + ' (latest)\n\
  251.                 2 - ' + atimanlegacy + ' (legacy)\n\
  252.                 3 - Back to main menu\n\
  253.                 (Type 1, 2 or 3)\n').strip()
  254.             if drvchoice == '1':
  255.                 self.details['drvtype'] = 'latest'
  256.                 self.details['manualchoice2'] = 'notmenu'
  257.                 break
  258.             elif drvchoice == '2':
  259.                 self.details['drvtype'] = 'oldest'
  260.                 self.details['manualchoice2'] = 'notmenu'
  261.                 break
  262.             elif drvchoice == '3':
  263.                 self.details['drvtype'] = 'oldest'
  264.                 self.details['manualchoice2'] = 'menu'
  265.                 break
  266.         if self.details['manualchoice2'] == 'menu':
  267.             objects.mainmenu()
  268.         else:
  269.             self.atireleasenum()
  270.  
  271.     def nvidiamanver(self):
  272.         while 1:
  273.             drvchoice = raw_input('\n\
  274.                 Select the version of the driver which would you like to install:\n\
  275.                 1 - ' + nvmanlatest + ' (latest)\n\
  276.                 2 - ' + nvmannewlegacy + ' (new legacy)\n\
  277.                 3 - ' + nvmanlegacy + ' (legacy)\n\
  278.                 4 - Back to main menu\n\
  279.                 (Type 1, 2, 3 or 4)\n').strip()
  280.             if drvchoice == '1':
  281.                 self.details['drvtype'] = 'latest'
  282.                 self.details['manualchoice1'] = 'notmenu'
  283.                 break
  284.             elif drvchoice == '2':
  285.                 self.details['drvtype'] = 'middle'
  286.                 self.details['manualchoice1'] = 'notmenu'
  287.                 break
  288.             elif drvchoice == '3':
  289.                 self.details['drvtype'] = 'oldest'
  290.                 self.details['manualchoice1'] = 'notmenu'
  291.                 break
  292.             elif drvchoice == '4':
  293.                 #self.details['drvtype'] = 'oldest'
  294.                 self.details['manualchoice1'] = 'menu'
  295.                 break
  296.         if self.details['manualchoice1'] == 'menu':
  297.             objects.mainmenu()
  298.         else:
  299.             self.nvreleasenum()
  300.  
  301.     def manualdetails(self):
  302.         while 1:
  303.             drvchoice = raw_input('\n\
  304.             Select the kind of driver which would you like to install:\n\
  305.             1 - ATI\n\
  306.             2 - NVIDIA\n\
  307.             3 - Back to main menu\n\
  308.             (Type either 1 or 2)\n').strip()
  309.             if drvchoice == '1':
  310.                 self.details['cardbrand'] = 'ati'
  311.                 self.details['manualchoice'] = 'notmenu'
  312.                 break
  313.             elif drvchoice == '2':
  314.                 self.details['cardbrand'] = 'nvidia'
  315.                 self.details['manualchoice'] = 'notmenu'
  316.                 break
  317.             elif drvchoice == '3':
  318.                 self.details['manualchoice'] = 'menu'
  319.                 break
  320.         if self.details['manualchoice'] == 'menu':
  321.             objects.mainmenu()
  322.         else:
  323.             if self.details['cardbrand'] == 'ati':
  324.                 self.atimanver()
  325.             elif self.details['cardbrand'] == 'nvidia':
  326.                 self.nvidiamanver()
  327.         
  328.     
  329.     
  330.     def nvreleasenum(self):
  331.         if self.details['drvtype'] == 'latest':
  332.             version = '1.0-' + nvmanlatest#9746
  333.         elif self.details['drvtype'] == 'middle':
  334.             version = '1.0-' + nvmannewlegacy#9631
  335.         elif self.details['drvtype'] == 'oldest':
  336.             version = '1.0-' + nvmanlegacy#7184
  337.         self.details['ver'] = version#add the version of the driver (e.g. '1.0-9746') to the "details" list
  338.  
  339.     def atireleasenum(self):
  340.         if self.details['drvtype'] == 'latest':
  341.             version = atimanlatest#'8.33.6'
  342.         elif self.details['drvtype'] == 'middle':#doesn't exist
  343.             version = 'none'
  344.         elif self.details['drvtype'] == 'oldest':
  345.             version = atimanlegacy#'8.28.8'
  346.         self.details['ver'] = version#add the version of the driver (e.g. '1.0-9746') to the "details" list
  347.  
  348.     #FUNCTIONS TO EDIT THE NVIDIA BUILD SCRIPTS
  349.  
  350.     def strippedver(self):
  351.         complete = self.details['ver']
  352.         stripped = complete.split('1.0-')
  353.         stripped.remove('')
  354.         self.details['strippedver'] = stripped[0]#the stripped version of the driver (e.g. 9746)
  355.         next = int(stripped[0]) + 2#the next version of the driver (needed by the Debian scripts)
  356.         self.details['nextver'] =  '1.0.' + str(next)#(e.g. '1.0.9746')
  357.  
  358.     def changelog(self):
  359.         lines = []
  360.         if self.details['drvtype'] == 'oldest':
  361.             file1 = '/usr/share/envy/nvidia-graphics-drivers-legacy/debian/changelog'
  362.         else: 
  363.             file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/changelog'
  364.         #nvidia-graphics-drivers (1.0.9746-2) unstable; urgency=low
  365.         #release = '1.0.' + self.details['strippedver'] + '-100'
  366.         versiontrick = str(int(self.details['strippedver']) +1)#trick
  367.         release = '1:1.0.' + versiontrick#use the version trick
  368.         opsystem = self.details['osname']
  369.         if self.details['drvtype'] == 'oldest':
  370.             pat1 = re.compile('nvidia-graphics-drivers-legacy (\(.+\)) (.+); urgency=low')
  371.         else: 
  372.             pat1 = re.compile('nvidia-graphics-drivers (\(.+\)) (.+); urgency=low')
  373.         text = open(file1, 'r')
  374.         optext = text.readlines()
  375.         for line in optext:
  376.             m1 = pat1.match(line)
  377.             if m1:
  378.                 if self.details['drvtype'] == 'oldest':
  379.                     line = 'nvidia-graphics-drivers-legacy (' + release + ') ' + opsystem + '; urgency=low\n'
  380.                 else: 
  381.                     line = 'nvidia-graphics-drivers (' + release + ') ' + opsystem + '; urgency=low\n'
  382.                 lines.append(line)
  383.             else:
  384.                 lines.append(line)
  385.         text.close()
  386.         sep = ''
  387.         modtext = open(file1, 'w')
  388.         a = sep.join(lines)
  389.         modtext.write(a)
  390.         modtext.close()
  391.     
  392.     def rules(self):
  393.         if self.details['drvtype'] != 'oldest':
  394.             lines = []
  395.             #if self.details['drvtype'] == 'oldest':
  396.             #    file1 = '/usr/share/envy/nvidia-graphics-drivers-legacy/debian/rules'
  397.             #else: 
  398.             file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/rules'
  399.             #nvidia-graphics-drivers (1.0.9746-2) unstable; urgency=low
  400.             release = '1.0.' + self.details['strippedver']
  401.             #opsystem = self.details['osname']
  402.             pat1 = re.compile('latest:=(.+)\n')
  403.             text = open(file1, 'r')
  404.             optext = text.readlines()
  405.             for line in optext:
  406.                 m1 = pat1.match(line)
  407.                 if m1:
  408.                     ##line = 'latest:=' + release + '\n'
  409.                     line = 'latest:=' + '1.0.' + nvmanlatest + '\n'
  410.                     #else: line = 'nvidia-graphics-drivers (' + release + ') ' + opsystem + '; urgency=low\n'
  411.                     lines.append(line)
  412.                 else:
  413.                     lines.append(line)
  414.             text.close()
  415.             sep = ''
  416.             modtext = open(file1, 'w')
  417.             a = sep.join(lines)
  418.             modtext.write(a)
  419.             modtext.close()
  420.  
  421.     def upstream(self):
  422.         lines = []
  423.         if self.details['drvtype'] == 'oldest':
  424.             file1 = '/usr/share/envy/nvidia-graphics-drivers-legacy/debian/upstream_info'
  425.         else: 
  426.             file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/upstream_info'
  427.         #nvidia-graphics-drivers (1.0.9746-2) unstable; urgency=low
  428.         release = self.details['strippedver']
  429.         next = self.details['nextver']
  430.         pat1 = re.compile('RELEASE=.+(.*)')
  431.         pat2 = re.compile('NEXTVER=.+(.*)')
  432.         text = open(file1, 'r')
  433.         optext = text.readlines()
  434.         for line in optext:
  435.             m1 = pat1.match(line)
  436.             m2 = pat2.match(line)
  437.             if m1:
  438.                 line = 'RELEASE=' + release + '\n'
  439.                 lines.append(line)
  440.             elif m2:
  441.                 line = 'NEXTVER='+ next + '\n'
  442.                 lines.append(line)
  443.             else:
  444.                 lines.append(line)
  445.         text.close()
  446.         sep = ''
  447.         modtext = open(file1, 'w')
  448.         a = sep.join(lines)
  449.         modtext.write(a)
  450.         modtext.close()
  451.         
  452.     def control(self):
  453.         if self.details['drvtype'] != 'oldest':
  454.             osdepend = ['dapper']
  455.             lines = []
  456.             #if self.details['drvtype'] == 'oldest':
  457.             #    file1 = '/usr/share/envy/nvidia-graphics-drivers-legacy/debian/rules'
  458.             #else: 
  459.             file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/control.in'
  460.             #nvidia-graphics-drivers (1.0.9746-2) unstable; urgency=low
  461.             xreleasenew = '>= 1:7.0.0'
  462.             xreleaseold = '>= 7.0.0'#only for Dapper
  463.             #opsystem = self.details['osname']
  464.             pat1 = re.compile('Depends\: nvidia\-kernel\-\#VERSION\#\, x11\-common \((.*)\)\, \$\{shlibs\:Depends\}\n')
  465.             text = open(file1, 'r')
  466.             optext = text.readlines()
  467.             for line in optext:
  468.                 m1 = pat1.match(line)
  469.                 if m1:
  470.                     ##line = 'latest:=' + release + '\n'
  471.                     if self.details['osname'] in self.legacyos:
  472.                         release = xreleaseold
  473.                     else:
  474.                         release = xreleasenew
  475.                     line = 'Depends: nvidia-kernel-#VERSION#, x11-common (' + release + '), ${shlibs:Depends}\n'
  476.                     #else: line = 'nvidia-graphics-drivers (' + release + ') ' + opsystem + '; urgency=low\n'
  477.                     lines.append(line)
  478.                 else:
  479.                     lines.append(line)
  480.             text.close()
  481.             sep = ''
  482.             modtext = open(file1, 'w')
  483.             a = sep.join(lines)
  484.             modtext.write(a)
  485.             modtext.close()
  486.     
  487.  
  488.             
  489.     def nvidiapkgmake(self):
  490.         #if self.details['drvtype'] == 'oldest':
  491.         #    nvdistinction = 'nvidia-graphics-drivers-legacy'
  492.         #else:
  493.         if self.details['drvtype'] == 'oldest':
  494.             nvdistinction = 'nvidia-graphics-drivers-legacy'
  495.         else:
  496.             nvdistinction = 'nvidia-graphics-drivers'
  497.         os.system('sudo chmod +x /usr/share/envy/' + nvdistinction + '/*.run')
  498.         os.system('cd /usr/share/envy/' + nvdistinction + '/ && sudo dpkg-buildpackage -b -uc')
  499.     
  500.     def nvidiakcommon(self):#Make sure this file is installed on Etch
  501.         nvkcommon = []
  502.         p = os.popen('sudo aptitude show nvidia-kernel-common')
  503.         indentifier = re.compile('.*State\:(.*)\n')
  504.         for line in p:#self.completetxt:#self.logged:
  505.             m1 = indentifier.match(line)
  506.             if m1:
  507.                 id = m1.group(1).strip().lower()
  508.                 if id == 'installed':
  509.                     nvkcommon.append('yes')
  510.         #print nvkcommon
  511.         if 'yes' not in nvkcommon:
  512.             print 'ENVY ERROR: nvidia-kernel-common is not installed and cannot be installed!'
  513.         else:
  514.             print 'OK: nvidia-kernel-common is installed'
  515.         
  516.     
  517.     def nvpkginstall1(self):
  518.         drvname = self.details['drvname']
  519.         #print 'Using version: ' + drvname#Rimuovere
  520.         os.system('sudo apt-get install -f -y')
  521.         os.system('sudo apt-get install -y nvidia-kernel-common')#needed by Etch
  522.         if self.details['osname'] == 'etch':
  523.             self.nvidiakcommon()#this should throw an error and make Envy abort on Etch if needed
  524.         if self.details['drvtype'] == 'oldest':#TEMPORARY FIX
  525.             os.system('sudo apt-get install -y nvidia-settings nvidia-xconfig')
  526.         #    os.system('sudo apt-get install -y nvidia-legacy-kernel-source')
  527.         #os.system('sudo apt-get install -y nvidia-glx-legacy')
  528.         #os.system('sudo apt-get install -y nvidia-glx-legacy-dev')
  529.         
  530.         if self.details['drvtype'] == 'oldest':
  531.             os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-legacy-kernel-source*.deb')
  532.         else:
  533.             os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-kernel-source_*.deb')#what if nvidia-new-kernel-source
  534.         
  535.             #os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx_*.deb')
  536.             #os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx-dev_*.deb')
  537.         #elif self.details['drvtype'] == 'latest':
  538.         #    os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-new-kernel-source_*.deb')
  539.         ##os.system('sudo dpkg -i nvidia-glx_' + drvname + '*.deb')
  540.         ##os.system('sudo dpkg -i nvidia-glx-dev_' + drvname + '*.deb')
  541.         ##os.system('sudo dpkg -i nvidia-kernel-source_' + drvname + '*.deb')
  542.  
  543.     def nvpkginstall2(self):
  544.         drvname = self.details['drvname']
  545.         #print 'Using version: ' + drvname#Rimuovere
  546.         os.system('sudo rm /usr/lib/nvidia/libGL.so.1*')
  547.         os.system('sudo apt-get -y remove --purge nvidia-glx-new')
  548.         os.system('sudo apt-get install -f -y')
  549.         if self.details['drvtype'] == 'oldest':#TEMPORARY FIX
  550.             os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx-legacy_*.deb')
  551.             #os.system('sudo apt-get install -y nvidia-glx-legacy-dev')#NOT NEEDED
  552.         else:
  553.             #os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-kernel-source_*.deb')
  554.             os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx_*.deb')
  555.             #os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx-dev_*.deb')#NOT NEEDED
  556.         #elif self.details['drvtype'] == 'latest':
  557.         #    os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx-new_*.deb')
  558.         #    os.system('cd /usr/share/envy/ && sudo dpkg -i nvidia-glx-new-dev_*.deb')
  559.  
  560.  
  561.     
  562.     def nvrmdeb(self):
  563.         #Remove any old fglrx debs from /usr/src/: 
  564.         os.system('sudo rm /usr/src/nvidia-kernel*.deb')
  565.         os.system('sudo rm /usr/src/nvidia-legacy-kernel*.deb')#useful?
  566.         os.system('sudo rm /usr/src/nvidia-new-kernel*.deb')
  567.     
  568.     def nvkmod(self):#compile ATI kernel module
  569.         os.system('sudo module-assistant prepare')
  570.         os.system('sudo module-assistant update')
  571.         if self.details['osname'] != 'etch':
  572.             glx = 'nvidia'
  573.             glxlegacy = 'nvidia-legacy-kernel-source'
  574.         else:
  575.             glx = 'nvidia'
  576.             glxlegacy = 'nvidia-legacy-kernel-source'
  577.         if self.details['drvtype'] != 'oldest':#TEMPORARY FIX
  578.             os.system('sudo module-assistant build ' + glx)#CHECK IF ITS NAME HAS CHANGED
  579.             os.system('sudo module-assistant install ' + glx)
  580.         else:
  581.             os.system('sudo module-assistant build ' + glxlegacy)
  582.             os.system('sudo module-assistant install ' + glxlegacy) 
  583.         os.system('sudo depmod -a')
  584.     
  585.     
  586.     def buildclean(self):
  587.         if self.details['drvtype'] == 'oldest':
  588.             nvdistinction = 'nvidia-graphics-drivers-legacy'
  589.             glx = 'nvidia-glx-legacy'
  590.             src = 'nvidia-legacy-kernel'
  591.         else: 
  592.             nvdistinction = 'nvidia-graphics-drivers'
  593.             glx = 'nvidia-glx'
  594.             src = 'nvidia-kernel'
  595.         os.system('sudo rm /usr/share/envy/*.deb')
  596.         os.system('sudo rm /usr/share/envy/*.asc')
  597.         os.system('sudo rm /usr/share/envy/*.changes')
  598.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/*stamp')
  599.         os.system('sudo rm -R /usr/share/envy/' + nvdistinction + '/NVIDIA-Linux-' + self.details['arch'] + '-' + self.details['ver'] + '-' + self.details['pkg'] )
  600.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/*.tar.gz')
  601.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/files')
  602.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/' + glx + '.postinst.debhelper')
  603.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/' + glx + '.postrm.debhelper')
  604.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/' + glx + '.prerm.debhelper')
  605.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/' + glx + '.substvars')
  606.         os.system('sudo rm /usr/share/envy/' + nvdistinction + '/debian/' + glx + '.substvars.bak')
  607.         os.system('sudo rm -R /usr/share/envy/' + nvdistinction + '/debian/' + glx)
  608.         os.system('sudo rm -R /usr/share/envy/' + nvdistinction + '/debian/' + glx + '-dev')
  609.         os.system('sudo rm -R /usr/share/envy/' + nvdistinction + '/debian/' + src + '-source')
  610.         os.system('sudo rm -R /usr/share/envy/' + nvdistinction + '/debian/' + glx + '-ia32')
  611.     
  612.     
  613.  
  614. #pkgver = drivertype()
  615.     def nvpkg(self):#There's no such thing for ATI cards
  616.         if self.details['arch'] == 'x86':#arca
  617.             pkg = 'pkg0' #pkg1
  618.         elif self.details['arch'] == 'x86_64':
  619.             pkg = 'pkg2'#paca
  620.         self.details['pkg'] = pkg
  621.         #return paca
  622.     
  623.     def nvvarsum(self):#md5
  624.         #arca = architecture()
  625.         if self.details['arch'] == 'x86':
  626.             if self.details['drvtype'] == 'latest':
  627.                 md5old = '991e03ceaff94fa8113ac04a541ec576'#575f988468f2c34a302da3d21e282689#cf0cdbd9099a6df028de429044e7f4da
  628.             elif self.details['drvtype'] == 'middle':#up to 96xx
  629.                 md5old = 'b0d721c962c4df1a028ae18416d7e862'#3676f622897d22f1815365b44139899e
  630.             else: md5old = '5bba3ec9075a42b33bf51b431123cc15'#149e5e9934387da5da6ebe21d694e82a#68cf7f155786daf6946b9daeb64c7a35#Legacy
  631.         elif self.details['arch'] == 'x86_64':
  632.             if self.details['drvtype'] == 'latest':
  633.                 md5old = '88eb6b856ab201dc00663165e10109f9'#c0afc66e1c21a9a54ba6719b8edd3166
  634.             elif self.details['drvtype'] == 'middle':#up to 96xx
  635.                 md5old = '64b88c6f405e7f2dd1607c0062c0c1f3'
  636.             else: md5old = 'cdca6c2eb474717935b76dd50c22323f'#332850387c4e7a4619753b856e3199e5#Legacy
  637.         #return md5old
  638.         self.details['md5old'] = md5old
  639.     
  640.     def ativarsum(self):#md5
  641.         #arca = architecture()
  642.         if self.details['arch'] == 'x86':
  643.             if self.details['drvtype'] == 'latest':
  644.                 md5old = 'bf056417ac6c57acdf5e5a6bb99a7dae'#c580c83cbf99007a4256fd40368cb2d9
  645.             elif self.details['drvtype'] == 'middle':#there's no middle driver for ATI
  646.                 md5old = 'none'
  647.             else: md5old = '58189d7cc3625e399b1a434df893100f'#32 bit Legacy
  648.         elif self.details['arch'] == 'x86_64':
  649.             if self.details['drvtype'] == 'latest':
  650.                 md5old = 'bf056417ac6c57acdf5e5a6bb99a7dae'#the same as 32bit
  651.             elif self.details['drvtype'] == 'middle':#there's no middle driver for ATI
  652.                 md5old = 'none'
  653.             else: md5old = '58189d7cc3625e399b1a434df893100f'#64bit Legacy
  654.         #return md5old
  655.         self.details['md5old'] = md5old
  656.         
  657.  
  658.     '''THE OBJECT WILL CHOOSE THE FUNCTION TO CALL ACCORDING TO THE DRIVER'''
  659.     def nvpkgname(self):#the name of the Nvidia installer
  660.         #driver = 'NVIDIA-Linux-' + arca + '-' + vera + '-' + paca + '.run'
  661.         driver = 'NVIDIA-Linux-' + self.details['arch'] + '-' + self.details['ver'] + '-' + self.details['pkg'] + '.run'#architecture,version,pkg
  662.         #return driver#pkgname
  663.         self.details['drvname'] = driver
  664.     def atipkgname(self):
  665.         if self.details['drvtype'] == 'oldest':#the name of the OLD ATI installer
  666.             driver = 'ati-driver-installer-' + self.details['ver'] + '.run'#version
  667.         else:#the name of the NEW ATI installer
  668.             driver = 'ati-driver-installer-' + self.details['ver'] + '-x86.x86_64.run'#version
  669.         self.details['drvname'] = driver
  670.     
  671.     def nvftpfolder(self):
  672.         nvidiaftp = 'Linux-' + self.details['arch'] + '/' + self.details['ver']
  673.         self.details['nvftpdir'] = nvidiaftp
  674.         #return nvidiaftp#ftpfolder
  675.     '''
  676.     IF THE LEGACY DRIVER IS SELECTED THE OBJECT SHOULD USE NVOLDADDR
  677.     '''
  678.     def nvaddress(self):
  679.         #if self.details['drvtype'] == 'oldest':#ONLY for the Legacy driver
  680.         #    wsite = ' http://download.nvidia.com/XFree86/'
  681.         #else:#for latest and newlegacy
  682.         wsite = ' http://us.download.nvidia.com/XFree86/'
  683.         nvweb = wsite + self.details['nvftpdir'] + '/' + self.details['drvname']
  684.         self.details['website'] = nvweb
  685.  
  686.    
  687.     def atiaddress(self):
  688.         if self.details['drvtype'] == 'oldest' and self.details['arch'] == 'x86_64':#ONLY for the Legacy driver
  689.             #if self.details['arch'] == 'x86_64':#only the 64bit of 8.28.8 is in a different folder
  690.             atiweb = ' https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/64bit/' + self.details['drvname']
  691.         else: atiweb = ' https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/' + self.details['drvname']
  692.         self.details['website'] = atiweb
  693.     
  694.     def md5get(self):
  695.         cksum = os.popen('md5sum ' + self.details['driverpath'] + self.details['drvname'])
  696.         pat1 = re.compile('(.+)  (.*)\n')
  697.         optext = cksum.readlines()
  698.         for line in optext:
  699.             m1 = pat1.match(line)
  700.             md5 = m1.group(1).strip()
  701.             if m1:
  702.                 self.details['md5new'] = md5
  703.     
  704.     def getdriver(self):
  705.         if self.details['cardbrand'] == 'nvidia':
  706.             if self.details['drvtype'] == 'oldest':
  707.                 self.details['driverpath'] = '/usr/share/envy/nvidia-graphics-drivers-legacy/'
  708.             else:
  709.                 self.details['driverpath'] = '/usr/share/envy/nvidia-graphics-drivers/'
  710.         else:#if ATI
  711.             self.details['driverpath'] = '/usr/share/envy/'
  712.         driverlocation = self.details['driverpath'] + self.details['drvname']
  713.         driverexists = os.path.isfile(driverlocation)
  714.         if driverexists:
  715.             print 'An installer has been detected'
  716.             self.md5get()
  717.             print 'md5new: ' + self.details['md5new']#md5new
  718.             print 'md5sumold: ' + self.details['md5old']
  719.             if self.details['md5new'] != self.details['md5old']: #md5new 
  720.                 print 'ENVY ERROR: md5 Error! Trying to fetch the driver from the website'
  721.                 os.remove(self.details['driverpath'] + self.details['drvname'])
  722.                 self.getdriver()#CHECK
  723.         else:#If the driver installer can't be found on your hard disk
  724.             print 'No installer detected'
  725.             print 'Download of the driver in progress, please wait'
  726.             os.system('cd ' + self.details['driverpath'] + '&& sudo wget -c --tries=2 --timeout=20 --no-check-certificate' + self.details['website'])
  727.             self.md5get()
  728.             print 'md5new: ' + self.details['md5new']#md5new
  729.             print 'md5sumold: ' + self.details['md5old']
  730.             if self.details['md5new'] != self.details['md5old']:
  731.                 print 'ENVY ERROR: md5 Error! Operation aborted'
  732.                 sys.exit()
  733.     
  734.     def atipkgmake(self):
  735.         a = os.uname()[2]
  736.         b = list(a)
  737.         c1 = a[0:6]
  738.         c = c1.strip()
  739.         kernels1 = ['2.6.13', '2.6.12', '2.6.11', '2.6.10', '2.6.14', '2.6.15', '2.6.16', '2.6.17', '2.6.18', '2.6.19']
  740.         kernels2 = ['2.6.20', '2.6.21', '2.6.22']#needs the patch
  741.         if self.details['osname'] not in self.legacyos:#only dapper and etch use bash
  742.             os.system('sudo ln -sf /bin/bash /bin/sh')#can cause problems on Dapper
  743.             #if c in kernels1:
  744.                 #if self.details['osname'] == 'edgy':
  745.             os.system('sh ' + self.details['drvname'] + ' --buildpkg Ubuntu/' + self.details['osname'])#name of the installer, dapper or edgy
  746.             #elif self.details['osname'] == 'feisty':#TEMPORARY FIX
  747.             #else:#needs the patch
  748.             os.system('sudo ln -sf /bin/dash /bin/sh')#can cause problems on Dapper
  749.         else:
  750.             os.system('sh ' + self.details['drvname'] + ' --buildpkg Ubuntu/' + self.details['osname'])#name of the installer, dapper or edgy
  751.  
  752.  
  753.     '''SCRIVERE ATIPKG INSTALL'''
  754.     def atipkginstall(self):
  755.         drvname = self.details['drvname']
  756.         #print 'Using version: ' + drvname#Rimuovere
  757.         os.system('sudo dpkg -i *.deb')
  758.         #os.system('sudo dpkg -i xorg-driver-fglrx_' + drvname + '*.deb')
  759.         #os.system('sudo dpkg -i fglrx-kernel-source_' + drvname + '*.deb')
  760.         #os.system('sudo dpkg -i fglrx-control_' + drvname + '*.deb')
  761.     
  762.     def atirmdeb(self):
  763.         #Remove any old fglrx debs from /usr/src/: 
  764.         os.system('sudo rm /usr/src/fglrx-kernel*.deb')
  765.     
  766.     def atikmod(self):#compile ATI kernel module
  767.         os.system('sudo module-assistant prepare')
  768.         os.system('sudo module-assistant update')
  769.         os.system('sudo module-assistant build fglrx')
  770.         os.system('sudo module-assistant install fglrx')
  771.         os.system('sudo depmod -a')
  772.     
  773.     def nvkernelcontrol(self):#ONLY FOR nvidiaclean
  774.         a = os.uname()[2]
  775.         b = list(a)
  776.         c1 = a[0:6]
  777.         c = c1.strip()
  778.         kernels1 = ['2.6.13', '2.6.12', '2.6.11', '2.6.10']#gcc-3.4
  779.         kernels2 = ['2.6.14', '2.6.15', '2.6.16', '2.6.17', '2.6.18', '2.6.19', '2.6.20']#gcc-4.0 or 4.1
  780.         systemname = self.details['osname']
  781.         if systemname == 'dapper':
  782.             if c in kernels1:
  783.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  784.             elif c in kernels2:
  785.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  786.         if systemname == 'edgy' or systemname == 'etch':
  787.             if c in kernels1:
  788.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  789.             elif c in kernels2:
  790.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  791.     
  792.         d = '/usr/src/' + 'kernel-headers-' + a#kernel headers path
  793.         f = '/usr/lib/xorg/modules'#xorg 32bit modules path
  794.         g = '/usr/lib64/xorg/modules'#xorg 64bit modules path
  795.         if os.path.isdir(d):
  796.             '''If the kernel is recompiled'''
  797.             print 'Recompiled kernel detected'
  798.             #self.details['kerneltype'] = 'recompiled'#THE KERNEL IS RECOMPILED
  799.             z = d + '/arch/i386/'
  800.             if not os.path.isdir(z):
  801.                 os.system('sudo mkdir -p' + ' ' + z)
  802.             if not os.path.isfile(z + 'Makefile.cpu'):
  803.                 '''If the Makefile.cpu does not exist'''
  804.                 if self.details['arch'] == 'x86_64':
  805.                     main.addmakefile64()
  806.                 else: main.addmakefile32()
  807.                 os.system('cd ' + d + ' && ' + 'sudo make prepare' + ' && ' + 'sudo make prepare scripts')
  808.                 if not os.path.isfile(z + 'Makefile.cpu'):
  809.                     '''If the Makefile.cpu still does not exist'''
  810.                     print 'ENVY ERROR: Makefile.cpu not found!'
  811.                     sys.exit()
  812.             if self.details['arch'] == 'x86_64':
  813.                 '''For Ubuntu 64bit'''
  814.                 #os.system('cd ' + foldername + ' && ' + 'sudo ./nvidia-installer -n -s --x-prefix=' + g + ' --kernel-source-path=' + d)
  815.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + g + ' --kernel-source-path=' + d)
  816.             else:
  817.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + f + ' --kernel-source-path=' + d)
  818.         else:
  819.             '''For Ubuntu default kernels'''
  820.             #self.details['kerneltype'] = 'default'#THE KERNEL IS NOT RECOMPILED
  821.             e = '/usr/src/' + 'linux-headers-' + a
  822.             if self.details['arch'] == 'x86_64':
  823.                 '''For Ubuntu 64bit'''
  824.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + g + ' --kernel-source-path=' + e)
  825.             else:
  826.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + f + ' --kernel-source-path=' + e)
  827.         os.system('sudo depmod -a')#DEPMOD
  828.     
  829.     def newkernelcontrol(self):
  830.         a = os.uname()[2]
  831.         b = list(a)
  832.         c1 = a[0:6]
  833.         c = c1.strip()
  834.         kernels1 = ['2.6.13', '2.6.12', '2.6.11', '2.6.10']#gcc-3.4
  835.         kernels2 = ['2.6.14', '2.6.15', '2.6.16', '2.6.17', '2.6.18', '2.6.19', '2.6.20']#gcc-4.0 or 4.1
  836.         systemname = self.details['osname']
  837.         if systemname == 'dapper':
  838.             if c in kernels1:
  839.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  840.             elif c in kernels2:
  841.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  842.         if systemname == 'edgy':
  843.             if c in kernels1:
  844.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  845.             elif c in kernels2:
  846.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  847.     
  848.         d = '/usr/src/' + 'kernel-headers-' + a#kernel headers path
  849.         f = '/usr/lib/xorg/modules'#xorg 32bit modules path
  850.         g = '/usr/lib64/xorg/modules'#xorg 64bit modules path
  851.         if os.path.isdir(d):
  852.             '''If the kernel is recompiled'''
  853.             print 'Recompiled kernel detected'
  854.             #self.details['kerneltype'] = 'recompiled'#THE KERNEL IS RECOMPILED
  855.             z = d + '/arch/i386/'
  856.             if not os.path.isdir(z):
  857.                 os.system('sudo mkdir -p' + ' ' + z)
  858.             if not os.path.isfile(z + 'Makefile.cpu'):
  859.                 '''If the Makefile.cpu does not exist'''
  860.                 if self.details['arch'] == 'x86_64':
  861.                     main.addmakefile64()
  862.                 else: main.addmakefile32()
  863.                 os.system('cd ' + d + ' && ' + 'sudo make prepare' + ' && ' + 'sudo make prepare scripts')
  864.                 if not os.path.isfile(z + 'Makefile.cpu'):
  865.                     '''If the Makefile.cpu still does not exist'''
  866.                     print 'ENVY ERROR: Makefile.cpu not found!'
  867.                     sys.exit()
  868.  
  869.     
  870.     def nvuninstalling(self):
  871.         if self.details['drvtype'] == 'oldest':
  872.             nvdistinction = 'nvidia-graphics-drivers-legacy'
  873.         else: 
  874.             nvdistinction = 'nvidia-graphics-drivers'
  875.         os.system('cd /usr/share/envy/' + nvdistinction + '/ && sudo sh ' + self.details['drvname'] + ' --uninstall')
  876.         '''UBUNTU AMD64 CHECK'''
  877.         '''Remove the makefile.cpu'''
  878.         #rmmakefile()
  879.         if self.details['osname'] != 'etch':
  880.             os.system('sudo apt-get -y install --reinstall linux-restricted-modules-`uname -r`')
  881.     '''
  882.     USE main.remove_ati_pkg()
  883.     def atiuninstalling():
  884.         os.system('sudo sh ' + self.details['drvname'] + ' --uninstall')
  885.         UBUNTU AMD64 CHECK
  886.         Remove the makefile.cpu
  887.         #rmmakefile()
  888.         os.system('sudo aptitude reinstall linux-restricted-modules-`uname -r`')
  889.     '''
  890.     
  891.     def xorgbackup(self):
  892.         os.system('sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf_backup_`date +%Y%m%d%H%M`')
  893.     
  894.     
  895.     def restoregcc(self):
  896.         a = os.uname()[2]
  897.         b = list(a)
  898.         c1 = a[0:6]
  899.         c = c1.strip()
  900.         kernels1 = ['2.6.13', '2.6.12', '2.6.11', '2.6.10']#gcc-3.4
  901.         kernels2 = ['2.6.14', '2.6.15', '2.6.16', '2.6.17', '2.6.18', '2.6.19', '2.6.20']#gcc-4.0 or 4.1
  902.         systemname = self.details['osname']
  903.         if systemname == 'dapper':
  904.             if c in kernels1:
  905.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  906.             elif c in kernels2:
  907.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  908.         if systemname == 'edgy' or systemname == 'etch':
  909.             if c in kernels1:
  910.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  911.             elif c in kernels2:
  912.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  913.     
  914.     def nviconadd(self):
  915.          try:
  916.              shutil.copy('/usr/share/envy/nvidia-settings.desktop', '/usr/share/applications/')
  917.          except OSError:
  918.             pass
  919.     
  920.     def nviconrm(self):
  921.          a = os.path.isfile('/usr/share/applications/nvidia-settings.desktop')
  922.          try:
  923.              os.remove('/usr/share/applications/nvidia-settings.desktop')
  924.          except OSError:
  925.             pass
  926.     
  927.     def nvxorgset(self):
  928.         distrolst = ['edgy', 'etch', 'feisty']#THEY NEED COMPOSITE TO BE ENABLED ATM
  929.         systemname = self.details['osname']
  930.         if systemname in distrolst:
  931.             if self.details['drvtype'] == 'latest' or self.details['drvtype'] == 'middle':
  932.                 os.system('sudo /usr/bin/nvidia-xconfig --composite')#MAKE SURE that COMPOSITE is ENABLED
  933.                 #objects.removeaiglx()#just in case it was disabled
  934.                 try:
  935.                     if self.details['geforcego'] == 'true':#needed by geforce go 420 440
  936.                         os.system('sudo /usr/share/envy/legacy/nvidia-xconfig --use-display-device=DFP')
  937.                 except KeyError:
  938.                     pass
  939.             else:
  940.                 os.system('sudo /usr/share/envy/legacy/nvidia-xconfig --no-composite')#MAKE SURE that COMPOSITE is DISABLED
  941.                 #objects.disableaiglx()#disable AIGLX
  942.         else:  os.system('sudo /usr/share/envy/legacy/nvidia-xconfig')#for Dapper
  943.  
  944.     
  945.     def atixorgset(self):
  946.         distrolst = ['edgy', 'etch', 'feisty']#THEY NEED COMPOSITE and AIGLX TO BE DISABLED ATM
  947.         systemname = self.details['osname']
  948.         objects.disablecomposite()
  949.         #objects.disableaiglx()#disable AIGLX
  950.         #os.system('sudo aticonfig --initial --force')
  951.         #os.system('sudo aticonfig --overlay-type=Xv')
  952.         runme = Fglrx()
  953.         runme.file = '/etc/X11/xorg.conf'
  954.         runme.atifglrx()
  955.         
  956.  
  957.  
  958. class Fglrx:
  959.     def atifglrx(self):
  960.         drvlst = ['fbdev', 'vga', 'vesa', 'radeon', 'ati', 'fglrx']
  961.         #self.file = '/home/alberto/Desktop/xorg.prova'
  962.         lines = []
  963.         #pat2 = re.compile('.*Option.*\"Composite\".*\"(.+)\".*\n')
  964.         text = open(self.file, 'r')
  965.         optext = text.readlines()
  966.         pat1 = re.compile('.*Driver.*\"(.+)\".*\n')
  967.         for line in optext:
  968.             m1 = pat1.match(line)
  969.             #m2 = pat2.match(line)
  970.             if m1:
  971.                 drvstring = m1.group(1).strip()
  972.                 if drvstring in drvlst:
  973.                     line =     '\tDriver\t\"fglrx\"\n'
  974.                 lines.append(line)
  975.             #elif m2:
  976.             #    line = '>'#a bookmark to find the 3rd line we need to delete
  977.             #    lines.append(line)
  978.             else:
  979.                 lines.append(line)
  980.         text.close()
  981.         sep = ''
  982.         modtext = open(self.file, 'w')
  983.         a = sep.join(lines)
  984.         modtext.write(a)
  985.         modtext.close()
  986.  
  987.         lines1 = []
  988.         text1 = open(self.file, 'r')
  989.         optext1 = text1.readlines()
  990.         pat2 = re.compile('.*Option.*\"VideoOverlay\".*\".+\".*\n')
  991.         pat3 = re.compile('.*Option.*\"OpenGLOverlay\".*\".+\".*\n')
  992.         for line in optext1:
  993.             m2 = pat2.match(line)
  994.             m3 = pat3.match(line)
  995.             if m2:
  996.                 line =     ''
  997.                 lines1.append(line)
  998.             elif m3:
  999.                 line = ''#a bookmark to find the 3rd line we need to delete
  1000.                 lines1.append(line)
  1001.             else:
  1002.                 lines1.append(line)
  1003.         text1.close()
  1004.         sep = ''
  1005.         modtext1 = open(self.file, 'w')
  1006.         a = sep.join(lines1)
  1007.         modtext1.write(a)
  1008.         modtext1.close()
  1009.         
  1010.         lastlines = []
  1011.         lasttext = open(self.file, 'r')
  1012.         newtext = lasttext.readlines()
  1013.         pat4 = re.compile('.*Driver.*\"fglrx\".*\n')#removes what remains of the option
  1014.         for lastline in newtext:
  1015.             m4 = pat4.match(lastline)
  1016.             if m4:
  1017.                 lastline = '\tDriver\t\"fglrx\"\n\tOption\t\"VideoOverlay\" \"on\"\n\tOption\t\"OpenGLOverlay" "off"\n'
  1018.                 lastlines.append(lastline)
  1019.             else: lastlines.append(lastline)
  1020.         lasttext.close()
  1021.         modtext2 = open(self.file, 'w')
  1022.         b = sep.join(lastlines)
  1023.         modtext2.write(b)
  1024.         modtext2.close()
  1025.  
  1026.  
  1027. class Composite:#removes any trace of the Composite Extension
  1028.  
  1029.     def operate(self):
  1030.         lines = []
  1031.         pat1 = re.compile('.*Section.*\"Extensions\".*\n')
  1032.         pat2 = re.compile('.*Option.*\"Composite\".*\"(.+)\".*\n')
  1033.         text = open(self.file, 'r')
  1034.         optext = text.readlines()
  1035.         for line in optext:
  1036.             m1 = pat1.match(line)
  1037.             m2 = pat2.match(line)
  1038.             if m1:
  1039.                 line = ''
  1040.                 lines.append(line)
  1041.             elif m2:
  1042.                 line = '>'#a bookmark to find the 3rd line we need to delete
  1043.                 lines.append(line)
  1044.             else:
  1045.                 lines.append(line)
  1046.         text.close()
  1047.         sep = ''
  1048.         modtext = open(self.file, 'w')
  1049.         a = sep.join(lines)
  1050.         modtext.write(a)
  1051.         modtext.close()
  1052.         
  1053.         lastlines = []
  1054.         lasttext = open(self.file, 'r')
  1055.         newtext = lasttext.readlines()
  1056.         pat3 = re.compile('>.*EndSection.*\n')#removes what remains of the option
  1057.         for lastline in newtext:
  1058.             m3 = pat3.match(lastline)
  1059.             if m3:
  1060.                 lastline = ''
  1061.                 lastlines.append(lastline)
  1062.             else: lastlines.append(lastline)
  1063.         lasttext.close()
  1064.         modtext1 = open(self.file, 'w')
  1065.         b = sep.join(lastlines)
  1066.         modtext1.write(b)
  1067.         modtext1.close()
  1068.  
  1069. class Compositechoice:
  1070.     #def init():
  1071.     #    self.file = 'none'#the address of the file
  1072.     #    self.operation = 'none'#Disable or Enable
  1073.     
  1074.     def choosecomposite(self):#Enable or Disable Composite
  1075.         objects.removecomposite()
  1076.         file = open(self.file, 'a')
  1077.         option = '\nSection "Extensions"\n\tOption "Composite" "' + self.operation + '"\nEndSection\n\n'
  1078.         file.write(option)
  1079.         file.close()
  1080.  
  1081. class Aiglx:#removes any trace of the Composite Extension
  1082.  
  1083.     def operate(self):
  1084.         lines = []
  1085.         pat1 = re.compile('.*Section.*\"ServerFlags\".*\n')
  1086.         pat2 = re.compile('.*Option.*\"AIGLX\".*\"(.+)\".*\n')
  1087.         text = open(self.file, 'r')
  1088.         optext = text.readlines()
  1089.         for line in optext:
  1090.             m1 = pat1.match(line)
  1091.             m2 = pat2.match(line)
  1092.             if m1:
  1093.                 line = ''
  1094.                 lines.append(line)
  1095.             elif m2:
  1096.                 line = '>'#a bookmark to find the 3rd line we need to delete
  1097.                 lines.append(line)
  1098.             else:
  1099.                 lines.append(line)
  1100.             #if m1:
  1101.             #    line = '>'
  1102.             #    lines.append(line)
  1103.             #elif m2:
  1104.             #    line = '>'#a bookmark to find the 3rd line we need to delete
  1105.             #    lines.append(line)
  1106.         text.close()
  1107.         sep = ''
  1108.         modtext = open(self.file, 'w')
  1109.         a = sep.join(lines)
  1110.         modtext.write(a)
  1111.         modtext.close()
  1112.         
  1113.         lastlines = []
  1114.         lasttext = open(self.file, 'r')
  1115.         newtext = lasttext.readlines()
  1116.         pat3 = re.compile('>.*EndSection.*\n')#removes what remains of the option
  1117.         pat4 = re.compile('>.*\n')#removes what remains of the option
  1118.         for lastline in newtext:
  1119.             m3 = pat3.match(lastline)
  1120.             #m4 = pat4.match(lastline)
  1121.             if m3:
  1122.                 lastline = ''
  1123.                 lastlines.append(lastline)
  1124.             #elif m4:
  1125.             else: lastlines.append(lastline)
  1126.         lasttext.close()
  1127.         modtext1 = open(self.file, 'w')
  1128.         b = sep.join(lastlines)
  1129.         modtext1.write(b)
  1130.         modtext1.close()
  1131.  
  1132. class Aiglxchoice:
  1133.     #def init():
  1134.     #    self.file = 'none'#the address of the file
  1135.     #    self.operation = 'none'#Disable or Enable
  1136.     
  1137.     def chooseaiglx(self):#Enable or Disable AIGLX
  1138.         objects.removeaiglx()
  1139.         file = open(self.file, 'a')
  1140.         option = '\nSection "ServerFlags"\n\tOption "AIGLX" "' + self.operation + '"\nEndSection\n\n'
  1141.         file.write(option)
  1142.         file.close()
  1143.  
  1144. '''DE\BLACKLIST FGLRX OR NVIDIA'''
  1145. class Chooselist:
  1146.     def init(self):
  1147.         self.driver = 'none'#'fglrx', 'nvidia' or ''
  1148.     def blacklist(self):
  1149.         '''restore Ubuntu original linux-restricted-modules-common'''
  1150.         restrictedblk = open('/etc/default/linux-restricted-modules-common', 'w')
  1151.         restrictedblk.write('# This file is sourced from the linux-restricted-modules-common init\n\
  1152.     # script and is used to disable the link-on-boot feature, one module\n\
  1153.     # at a time.  This can be useful if you want to use hand-compiled\n\
  1154.     # versions of one or more modules, but keep linux-restricted-modules\n\
  1155.     # installed on your system, or just to disable modules you don\'t use\n\
  1156.     # and speed up your boot process by a second or two.\n\
  1157.     #\n\
  1158.     # Use a space-separated list of modules you wish to not have linked\n\
  1159.     # on boot.  The following example shows a (condensed) list of all\n\
  1160.     # modules shipped in the linux-restricted-modules packages:\n\
  1161.     #\n\
  1162.     # DISABLED_MODULES="ath_hal fc fglrx ltm nv"\n\
  1163.     #\n\
  1164.     # Note that disabling "fc" disables all fcdsl drivers, "ltm" disables\n\
  1165.     # ltmodem and ltserial, and "nv" disables both the nvidia drivers.\n\
  1166.     # You can also name each module individually, if you prefer a subset.\n\
  1167.     \n\
  1168.     DISABLED_MODULES="' + self.driver + '"\n')
  1169.         restrictedblk.close()
  1170.